package com.mp.approvalreq.servlet.redpoint;


import com.mp.approvalreq.entity.NewRedPoint;
import com.mp.approvalreq.service.RedPointServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import com.plusmoney.message.SuccessMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 审批栏目总红点
 */
@WebServlet("/getRedPoints")
public class GetRedPoints extends AbstractServlet {

    private static final Logger logger = LoggerFactory.getLogger(GetRedPoints.class);

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
        try {
            User user = getReqUser(req);

            User simpleUser = new User();
            simpleUser.setCompanyId(user.getCompanyId());
            simpleUser.setCompanyInfoId(user.getCompanyInfoId());
            user = simpleUser;

            RedPointServicePrx redPointServicePrx = ServiceUtils.getRedPointServicePrx();
            NewRedPoint redPoint = redPointServicePrx.getRedPoints(user);

            String msg = SuccessMsg.getDefaultMsg(redPoint);

            logger.info("返回json:{}", msg);

            printJson(resp, msg);
        } catch (Throwable e) {
            onThrowable(req, resp, e);
        }
    }

}
